<%@page import="antlr.StringUtils"%>
<%@page import="beans.Chapterbean"%>
<%@page import="dao.Course"%>
<%@page import="beans.Coursebean"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
    String path = request.getContextPath();
			String basePath = request.getScheme() + "://"
					+ request.getServerName() + ":" + request.getServerPort()
					+ path + "/";
%>
<%
	Course course = (Course)session.getAttribute("course");
	int counts = course.getChaptercounts();
	Chapterbean chapterService = new Chapterbean();
	List<String> list = chapterService.getChapters(course.getCourseid(), counts);
	int size = list.size();
	StringBuffer buffer = new StringBuffer();
	for(String str:list){
	    buffer.append(str).append(",");
	}
	buffer.deleteCharAt(buffer.length()-1);
	String chapterids = buffer.toString();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>添加章节</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<style type="text/css">
body {
	font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica,
		sans-serif;
	color: #4f6b72;
	text-align: center;
	background: #E6EAE9;
}

#container {
	margin-left: auto;
	margin-right: auto;
	width: 650px;
	height: 600px;
	background: #f8f8f8;
	border: 2px solid #777;
	display: block;
	vertical-align: middle;
}

.ele {
	margin-top: 30px;
	margin-botton: 30px;
	text-align: center;
	width: 100%;
	display: block;
	vertical-align: middle;
}
</style>
<script type="text/javascript">
function checkData(){
	var chapterId = document.getElementById("chapterId").value.trim();
	var chapterName = document.getElementById("chapterName").value.trim();
	var structureChart = document.getElementById("strctureChart").value.trim();
	var demand = document.getElementById("demand").value.trim();
	if(chapterId !="choose" && chapterName !="" && structureChart!="" && demand !=""){
			return true;					
	}else{
		alert("请填写完整！");
		return false;
	}
}

</script>
</head>
<body>
	<h2>添加章节信息</h2>
	<div id="container">
		<form name="courseForm" method="post" enctype="multipart/form-data" 
			action="./servlet/ChapterManageServlet?action=add"
			onsubmit="return checkData()">
			<div class="ele">
				<label> 选择章节： <select name="chapterId" id="chapterId">
						<option value="choose" selected="selected">请选择章节</option>
				</select>
			</div>
			<div class="ele">
				<label> 章节名称： </label> <input type="text" id="chapterName"
					name="chapterName" >
			</div>
			<div class="ele">
				<label> 知识结构图： </label> <input type="file" name="strctureChart"
					id="strctureChart" readonly="readonly">
			</div>
			<div class="ele">
				<label> 大纲要求： </label>
				<textarea name="demand" id="demand" rows="7" cols="65"></textarea>
			</div>

			<div class="ele">
				<input type="submit" value="提交"> <input type="reset"
					value="取消">
			</div>
		</form>
	</div>
	<script type="text/javascript">
	var ids = "<%=chapterids%>";
	var options = ids.split(",");
	var obj = document.getElementById("chapterId");
	if(options.length > 0){
		for(var i=0;i<options.length;i++){		
			var str = "第";
			var value = options[i];
			if(value.charAt(value.length -2) =='0'){
				str = str + value.charAt(value.length-1);
			}else{
				str = str + value.substring(value.length-2);
			}
			str = str + "章";
			obj.options[i+1] = new Option(str,value);
		}
		}else{
			obj.options[1] = new Option("没有要添加的章节","null");
		}
	</script>
	<%
	    if (request.getAttribute("success") != null) {
				String str = (String) request.getAttribute("success");
				if ("true".equals(str)) {
				    out.write("<script>alert('添加成功！')</script>");
				} else if ("false".equals(str)) {
				    out.write("<script>alert('添加失败！')</script>");
				}
	    }
	%>
</body>
</html>
